package cn.dada.dadarecipes.community.comment.controller;

import cn.dada.dadarecipes.base.response.JsonResult;
import cn.dada.dadarecipes.community.comment.pojo.dto.CommentSaveParam;
import cn.dada.dadarecipes.community.comment.pojo.entity.Comment;
import cn.dada.dadarecipes.community.comment.pojo.vo.CommentVO;
import cn.dada.dadarecipes.community.comment.service.CommentService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@Api(tags = "02.04文章评论管理")
@RestController
@RequestMapping("/v1/article/comment/")
public class CommentController {
    @Autowired
    private CommentService commentService;



    /**
     * 控制器-查询评论列表
     * @param articleId
     * @return
     */
    @GetMapping("select")
    @ApiOperation("评论列表查询")
    @ApiImplicitParam(name = "articleId", value = "文章id", required = true)
    public JsonResult selectComment(@RequestParam("articleId") Long articleId) {
        log.debug("控制器-查询评论列表: articleId={}",articleId);
        List<CommentVO> list = commentService.selectComment(articleId);
        return JsonResult.ok(list);
    }

    /**
     * 控制器-保存文章评论
     * @param commentParam
     * @return
     */
    @PostMapping("save")
    @ApiOperation("保存文章评论")
    public JsonResult saveComment(CommentSaveParam commentParam, @ApiIgnore HttpSession session) {
        log.debug("控制器-保存文章评论: {} {}", commentParam,session);
        commentService.saveComment(commentParam,session);
        return JsonResult.ok();
    }

    /**
     * 控制器-删除评论
     * @param commentId
     * @param session
     * @return
     */
    @PostMapping("delete")
    @ApiOperation("删除评论")
    @ApiImplicitParam(name = "commentId", value = "评论id", required = true)
    public JsonResult deleteComment(Long commentId, @ApiIgnore HttpSession session) {
        log.debug("控制器-删除评论: {},{}", commentId,session);
        commentService.deleteComment(commentId,session);
        return JsonResult.ok();
    }
}
